package com.burstly.lib.component.networkcomponent.jumptap;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Handler;
import android.os.Looper;
import android.util.Log;
import android.view.KeyEvent;
import android.view.MotionEvent;
import android.view.View;
import com.burstly.lib.component.AbstractAdaptor;
import com.burstly.lib.component.IBurstlyAdaptor.BurstlyAdType;
import com.burstly.lib.component.IBurstlyAdaptorListener;
import com.burstly.lib.component.IBurstlyAdaptorListener.FullscreenInfo;
import com.burstly.lib.component.activitylauncher.ActivtyLauncher;
import com.burstly.lib.component.activitylauncher.IActivityLauncherSource;
import com.burstly.lib.component.networkcomponent.burstly.FullscreenOverlayContainer;
import com.burstly.lib.network.request.RequestManager;
import com.burstly.lib.util.LoggerExt;
import com.jumptap.adtag.JtAdInterstitial;
import com.jumptap.adtag.JtAdView;
import com.jumptap.adtag.JtAdViewListener;
import com.jumptap.adtag.JtAdWidgetSettings;
import com.jumptap.adtag.JtAdWidgetSettingsFactory;
import com.jumptap.adtag.utils.JtException;
import java.lang.ref.Reference;
import java.lang.ref.WeakReference;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.Map;

final class JumptapAdaptor extends AbstractAdaptor
  implements IActivityLauncherSource
{
  static final IBurstlyAdaptorListener.FullscreenInfo FULLSCREEN_INFO = new IBurstlyAdaptorListener.FullscreenInfo("jumptap", true);
  static final String NETWORK_NAME = "jumptap";
  static final String TAG = JumptapAdaptor.class.getSimpleName();
  static JumptapAdaptor sJumptapAdaptor;
  private final JumptapConfigurator mConfigurator;
  JtAdInterstitial mInterstitialView;
  private ActivtyLauncher mMLauncher;

  JumptapAdaptor(Context paramContext, String paramString)
  {
    super(paramContext, paramString);
    this.mTag = (paramString + " " + TAG);
    this.mConfigurator = new JumptapConfigurator();
    this.mMLauncher = new ActivtyLauncher(this, getContext()).setNetworkName("jumptap");
  }

  private void fixWindowVisibility(JtAdView paramJtAdView)
    throws Exception
  {
    try
    {
      Field localField = JtAdView.class.getDeclaredField("isWindowVisible");
      localField.setAccessible(true);
      localField.set(paramJtAdView, Boolean.TRUE);
      return;
    }
    catch (Exception localException)
    {
      LOG.logError(this.mTag, "Could not change visibility of JtAdView.isWindowVisible field. Can not proceed this view. Fail.", new Object[0]);
      throw localException;
    }
  }

  private void getAd(JtAdView paramJtAdView)
  {
    try
    {
      Method localMethod = JtAdView.class.getDeclaredMethod("loadUrlIfVisible", new Class[0]);
      localMethod.setAccessible(true);
      localMethod.invoke(paramJtAdView, new Object[0]);
      return;
    }
    catch (Exception localException)
    {
      LOG.logError(this.mTag, "Can not invoke or find 'loadUrlIfVisible' in JtAdView class. Will fail by timeout.", new Object[0]);
    }
  }

  private void handleInterstitial()
    throws Exception
  {
    JtAdWidgetSettings localJtAdWidgetSettings = JtAdWidgetSettingsFactory.createWidgetSettings();
    this.mConfigurator.configure(localJtAdWidgetSettings);
    localJtAdWidgetSettings.setInterstitialshowTime(20);
    BurstlyInterstitialJtAdWrapper localBurstlyInterstitialJtAdWrapper = new BurstlyInterstitialJtAdWrapper(getContext(), localJtAdWidgetSettings);
    fixWindowVisibility(localBurstlyInterstitialJtAdWrapper);
    this.mInterstitialView = localBurstlyInterstitialJtAdWrapper;
    localBurstlyInterstitialJtAdWrapper.setAdViewListener(new JumptapListener(this, true));
    getAd(localBurstlyInterstitialJtAdWrapper);
  }

  public void beforeLaunch()
  {
    sJumptapAdaptor = this;
    JumptapActivity.sIsShowingNow = true;
  }

  protected void checkParameters(Map<String, ?> paramMap)
    throws IllegalArgumentException
  {
    this.mConfigurator.initConfigurator(paramMap);
  }

  public void destroy()
  {
    super.destroy();
    this.mInterstitialView = null;
    this.mMLauncher = null;
  }

  protected View doGetNewAd()
  {
    this.mConfigurator.setPrecacheInterstitial(false);
    try
    {
      if (this.mConfigurator.isInterstitial())
      {
        handleInterstitial();
      }
      else
      {
        JtAdWidgetSettings localJtAdWidgetSettings = JtAdWidgetSettingsFactory.createWidgetSettings();
        this.mConfigurator.configure(localJtAdWidgetSettings);
        BurstlyJtAdWrapper localBurstlyJtAdWrapper = new BurstlyJtAdWrapper(getContext(), localJtAdWidgetSettings);
        localBurstlyJtAdWrapper.setAdViewListener(new JumptapListener(this));
        fixWindowVisibility(localBurstlyJtAdWrapper);
        getAd(localBurstlyJtAdWrapper);
        return localBurstlyJtAdWrapper;
      }
    }
    catch (Exception localException)
    {
      getAdaptorListener().failedToLoad("jumptap", this.mConfigurator.isInterstitial(), Log.getStackTraceString(localException));
    }
    return null;
  }

  public IBurstlyAdaptor.BurstlyAdType getAdType()
  {
    if (this.mConfigurator.isInterstitial())
      return IBurstlyAdaptor.BurstlyAdType.INTERSTITIAL_AD_TYPE;
    return IBurstlyAdaptor.BurstlyAdType.BANNER_AD_TYPE;
  }

  public Intent getIntent()
  {
    return new Intent(getContext().getApplicationContext(), JumptapActivity.class);
  }

  public String getNetworkName()
  {
    return "jumptap";
  }

  public boolean isAllowedToLaunch()
  {
    return !JumptapActivity.sIsShowingNow;
  }

  public void onActivityNotFound(String paramString)
  {
    JumptapActivity.sIsShowingNow = false;
    sJumptapAdaptor = null;
  }

  public void onFailToLaunch(String paramString)
  {
    getAdaptorListener().failedToLoad("jumptap", this.mConfigurator.isInterstitial(), paramString);
  }

  public void onSuccesToLaunch()
  {
  }

  public View precacheAd()
  {
    return getNewAd();
  }

  public void precacheInterstitialAd()
  {
    this.mConfigurator.setPrecacheInterstitial(true);
    try
    {
      handleInterstitial();
      return;
    }
    catch (Exception localException)
    {
      String str = Log.getStackTraceString(localException);
      getAdaptorListener().failedToLoad("jumptap", true, str);
    }
  }

  void showActivity()
  {
    setHardwareAcceleration(this.mInterstitialView);
    this.mMLauncher.launchActivity();
  }

  public void showPrecachedInterstitialAd()
  {
    if (this.mInterstitialView != null)
    {
      IBurstlyAdaptorListener localIBurstlyAdaptorListener = getAdaptorListener();
      localIBurstlyAdaptorListener.didLoad("jumptap", true);
      localIBurstlyAdaptorListener.shownFullscreen(FULLSCREEN_INFO);
      showActivity();
    }
  }

  public boolean supports(String paramString)
  {
    return true;
  }

  private static class BurstlyInterstitialJtAdWrapper extends JtAdInterstitial
  {
    private static final String TAG = BurstlyInterstitialJtAdWrapper.class.getSimpleName();
    private boolean mAttached;

    BurstlyInterstitialJtAdWrapper(Context paramContext, JtAdWidgetSettings paramJtAdWidgetSettings)
      throws JtException
    {
      super(paramJtAdWidgetSettings);
    }

    public int getVisibility()
    {
      if (this.mAttached)
        return super.getVisibility();
      return 0;
    }

    protected void onAttachedToWindow()
    {
      this.mAttached = true;
      super.onAttachedToWindow();
    }

    protected void onDetachedFromWindow()
    {
      this.mAttached = false;
      super.onDetachedFromWindow();
    }

    public boolean onInterceptTouchEvent(MotionEvent paramMotionEvent)
    {
      try
      {
        boolean bool = super.onInterceptTouchEvent(paramMotionEvent);
        return bool;
      }
      catch (Exception localException)
      {
        JumptapAdaptor.LOG.logWarning(TAG, Log.getStackTraceString(localException), new Object[0]);
      }
      return true;
    }

    public boolean onKeyDown(int paramInt, KeyEvent paramKeyEvent)
    {
      try
      {
        boolean bool = super.onKeyDown(paramInt, paramKeyEvent);
        return bool;
      }
      catch (Exception localException)
      {
        JumptapAdaptor.LOG.logWarning(TAG, Log.getStackTraceString(localException), new Object[0]);
      }
      return true;
    }

    public boolean onKeyMultiple(int paramInt1, int paramInt2, KeyEvent paramKeyEvent)
    {
      try
      {
        boolean bool = super.onKeyMultiple(paramInt1, paramInt2, paramKeyEvent);
        return bool;
      }
      catch (Exception localException)
      {
        JumptapAdaptor.LOG.logWarning(TAG, Log.getStackTraceString(localException), new Object[0]);
      }
      return true;
    }

    public boolean onKeyPreIme(int paramInt, KeyEvent paramKeyEvent)
    {
      try
      {
        boolean bool = super.onKeyPreIme(paramInt, paramKeyEvent);
        return bool;
      }
      catch (Exception localException)
      {
        JumptapAdaptor.LOG.logWarning(TAG, Log.getStackTraceString(localException), new Object[0]);
      }
      return true;
    }

    public boolean onKeyShortcut(int paramInt, KeyEvent paramKeyEvent)
    {
      try
      {
        boolean bool = super.onKeyShortcut(paramInt, paramKeyEvent);
        return bool;
      }
      catch (Exception localException)
      {
        JumptapAdaptor.LOG.logWarning(TAG, Log.getStackTraceString(localException), new Object[0]);
      }
      return true;
    }

    public boolean onKeyUp(int paramInt, KeyEvent paramKeyEvent)
    {
      try
      {
        boolean bool = super.onKeyUp(paramInt, paramKeyEvent);
        return bool;
      }
      catch (Exception localException)
      {
        JumptapAdaptor.LOG.logWarning(TAG, Log.getStackTraceString(localException), new Object[0]);
      }
      return true;
    }

    public boolean onTrackballEvent(MotionEvent paramMotionEvent)
    {
      try
      {
        boolean bool = super.onTrackballEvent(paramMotionEvent);
        return bool;
      }
      catch (Exception localException)
      {
        JumptapAdaptor.LOG.logWarning(TAG, Log.getStackTraceString(localException), new Object[0]);
      }
      return true;
    }
  }

  private static class BurstlyJtAdWrapper extends JtAdView
  {
    private static final String TAG = BurstlyJtAdWrapper.class.getSimpleName();
    private boolean mAttached;

    BurstlyJtAdWrapper(Context paramContext, JtAdWidgetSettings paramJtAdWidgetSettings)
      throws JtException
    {
      super(paramJtAdWidgetSettings);
    }

    public int getVisibility()
    {
      if (this.mAttached)
        return super.getVisibility();
      return 0;
    }

    protected void onAttachedToWindow()
    {
      this.mAttached = true;
      super.onAttachedToWindow();
    }

    protected void onDetachedFromWindow()
    {
      this.mAttached = false;
      super.onDetachedFromWindow();
    }

    public boolean onInterceptTouchEvent(MotionEvent paramMotionEvent)
    {
      try
      {
        boolean bool = super.onInterceptTouchEvent(paramMotionEvent);
        return bool;
      }
      catch (Exception localException)
      {
        JumptapAdaptor.LOG.logWarning(TAG, Log.getStackTraceString(localException), new Object[0]);
      }
      return true;
    }

    public boolean onKeyDown(int paramInt, KeyEvent paramKeyEvent)
    {
      try
      {
        boolean bool = super.onKeyDown(paramInt, paramKeyEvent);
        return bool;
      }
      catch (Exception localException)
      {
        JumptapAdaptor.LOG.logWarning(TAG, Log.getStackTraceString(localException), new Object[0]);
      }
      return true;
    }

    public boolean onKeyMultiple(int paramInt1, int paramInt2, KeyEvent paramKeyEvent)
    {
      try
      {
        boolean bool = super.onKeyMultiple(paramInt1, paramInt2, paramKeyEvent);
        return bool;
      }
      catch (Exception localException)
      {
        JumptapAdaptor.LOG.logWarning(TAG, Log.getStackTraceString(localException), new Object[0]);
      }
      return true;
    }

    public boolean onKeyPreIme(int paramInt, KeyEvent paramKeyEvent)
    {
      try
      {
        boolean bool = super.onKeyPreIme(paramInt, paramKeyEvent);
        return bool;
      }
      catch (Exception localException)
      {
        JumptapAdaptor.LOG.logWarning(TAG, Log.getStackTraceString(localException), new Object[0]);
      }
      return true;
    }

    public boolean onKeyShortcut(int paramInt, KeyEvent paramKeyEvent)
    {
      try
      {
        boolean bool = super.onKeyShortcut(paramInt, paramKeyEvent);
        return bool;
      }
      catch (Exception localException)
      {
        JumptapAdaptor.LOG.logWarning(TAG, Log.getStackTraceString(localException), new Object[0]);
      }
      return true;
    }

    public boolean onKeyUp(int paramInt, KeyEvent paramKeyEvent)
    {
      try
      {
        boolean bool = super.onKeyUp(paramInt, paramKeyEvent);
        return bool;
      }
      catch (Exception localException)
      {
        JumptapAdaptor.LOG.logWarning(TAG, Log.getStackTraceString(localException), new Object[0]);
      }
      return true;
    }

    public boolean onTouchEvent(MotionEvent paramMotionEvent)
    {
      try
      {
        boolean bool = super.onTouchEvent(paramMotionEvent);
        return bool;
      }
      catch (Exception localException)
      {
        JumptapAdaptor.LOG.logWarning(TAG, Log.getStackTraceString(localException), new Object[0]);
      }
      return true;
    }

    public boolean onTrackballEvent(MotionEvent paramMotionEvent)
    {
      try
      {
        boolean bool = super.onTrackballEvent(paramMotionEvent);
        return bool;
      }
      catch (Exception localException)
      {
        JumptapAdaptor.LOG.logWarning(TAG, Log.getStackTraceString(localException), new Object[0]);
      }
      return true;
    }

    protected void onWindowVisibilityChanged(int paramInt)
    {
      if (!RequestManager.isOnline())
      {
        if (paramInt != 0)
          super.onWindowVisibilityChanged(paramInt);
        return;
      }
      super.onWindowVisibilityChanged(paramInt);
    }
  }

  private static class JumptapListener
    implements JtAdViewListener
  {
    private final Reference<JumptapAdaptor> mAdaptor;
    private Handler mHandler;
    private final boolean mIsInterstitial;
    private boolean mWasExpanded;

    JumptapListener(JumptapAdaptor paramJumptapAdaptor)
    {
      this(paramJumptapAdaptor, false);
    }

    JumptapListener(JumptapAdaptor paramJumptapAdaptor, boolean paramBoolean)
    {
      this.mAdaptor = new WeakReference(paramJumptapAdaptor);
      this.mIsInterstitial = paramBoolean;
      this.mHandler = new Handler(Looper.getMainLooper());
    }

    public void onAdError(JtAdView paramJtAdView, int paramInt1, int paramInt2)
    {
      JumptapAdaptor localJumptapAdaptor = (JumptapAdaptor)this.mAdaptor.get();
      if ((localJumptapAdaptor != null) && (!localJumptapAdaptor.isStopped()))
      {
        localJumptapAdaptor.getAdaptorListener().failedToLoad("jumptap", this.mIsInterstitial, "Jumptap error code: " + paramInt2);
        return;
      }
      JumptapAdaptor.LOG.logWarning(JumptapAdaptor.TAG, "Jumptap adaptor was garbage collected or adaptor stopped. Can not continue from onAdError", new Object[0]);
    }

    public void onBannerClicked(JtAdView paramJtAdView, int paramInt)
    {
      JumptapAdaptor localJumptapAdaptor = (JumptapAdaptor)this.mAdaptor.get();
      if ((localJumptapAdaptor != null) && (!localJumptapAdaptor.isStopped()))
      {
        localJumptapAdaptor.getAdaptorListener().adWasClicked("jumptap", this.mIsInterstitial);
        return;
      }
      JumptapAdaptor.LOG.logWarning(JumptapAdaptor.TAG, "Jumptap adaptor was garbage collected or adaptor stopped. Can not continue from onBannerClicked", new Object[0]);
    }

    public void onBeginAdInteraction(JtAdView paramJtAdView, int paramInt)
    {
    }

    public void onContract(JtAdView paramJtAdView, int paramInt)
    {
      JumptapAdaptor localJumptapAdaptor = (JumptapAdaptor)this.mAdaptor.get();
      if (this.mWasExpanded)
      {
        if ((localJumptapAdaptor == null) || (localJumptapAdaptor.isStopped()))
          break label88;
        Object localObject = paramJtAdView.getTag();
        if (!(localObject instanceof FullscreenOverlayContainer))
          break label74;
        FullscreenOverlayContainer localFullscreenOverlayContainer = (FullscreenOverlayContainer)localObject;
        if (localFullscreenOverlayContainer.isShowing())
          this.mHandler.post(localFullscreenOverlayContainer);
      }
      while (true)
      {
        this.mWasExpanded = false;
        return;
        label74: localJumptapAdaptor.getAdaptorListener().onCollapse("jumptap");
      }
      label88: JumptapAdaptor.LOG.logWarning(JumptapAdaptor.TAG, "Jumptap adaptor was garbage collected or adaptor stopped. Can not continue from onHide", new Object[0]);
    }

    public void onEndAdInteraction(JtAdView paramJtAdView, int paramInt)
    {
    }

    public void onExpand(JtAdView paramJtAdView, int paramInt)
    {
      JumptapAdaptor localJumptapAdaptor = (JumptapAdaptor)this.mAdaptor.get();
      if ((localJumptapAdaptor != null) && (!localJumptapAdaptor.isStopped()))
      {
        localJumptapAdaptor.getAdaptorListener().onExpand("jumptap", this.mIsInterstitial);
        this.mWasExpanded = true;
        return;
      }
      JumptapAdaptor.LOG.logWarning(JumptapAdaptor.TAG, "Jumptap adaptor was garbage collected or adaptor stopped. Can not continue from onExpand", new Object[0]);
    }

    public void onFocusChange(JtAdView paramJtAdView, int paramInt, boolean paramBoolean)
    {
    }

    public void onHide(JtAdView paramJtAdView, int paramInt)
    {
      JumptapAdaptor localJumptapAdaptor = (JumptapAdaptor)this.mAdaptor.get();
      if ((localJumptapAdaptor != null) && (!localJumptapAdaptor.isStopped()))
      {
        Object localObject = paramJtAdView.getTag();
        if ((localObject instanceof FullscreenOverlayContainer))
        {
          FullscreenOverlayContainer localFullscreenOverlayContainer = (FullscreenOverlayContainer)localObject;
          if (localFullscreenOverlayContainer.isShowing())
            this.mHandler.post(localFullscreenOverlayContainer);
          return;
        }
        localJumptapAdaptor.getAdaptorListener().onHide("jumptap");
        return;
      }
      JumptapAdaptor.LOG.logWarning(JumptapAdaptor.TAG, "Jumptap adaptor was garbage collected or adaptor stopped. Can not continue from onHide", new Object[0]);
    }

    public void onInterstitialDismissed(JtAdView paramJtAdView, int paramInt)
    {
      if (JumptapActivity.sJumptapActivity != null)
      {
        JumptapActivity.sJumptapActivity.finish();
        JumptapActivity.sJumptapActivity = null;
        JumptapAdaptor localJumptapAdaptor = (JumptapAdaptor)this.mAdaptor.get();
        if ((localJumptapAdaptor != null) && (!localJumptapAdaptor.isStopped()))
          localJumptapAdaptor.getAdaptorListener().dismissedFullscreen(JumptapAdaptor.FULLSCREEN_INFO);
      }
      else
      {
        return;
      }
      JumptapAdaptor.LOG.logWarning(JumptapAdaptor.TAG, "Jumptap adaptor was garbage collected or adaptor stopped. Can not continue from onInterstitialDismissed", new Object[0]);
    }

    public void onLaunchActivity(JtAdView paramJtAdView, int paramInt)
    {
      JumptapAdaptor localJumptapAdaptor = (JumptapAdaptor)this.mAdaptor.get();
      if ((localJumptapAdaptor != null) && (!localJumptapAdaptor.isStopped()))
      {
        localJumptapAdaptor.getAdaptorListener().shownFullscreen(JumptapAdaptor.FULLSCREEN_INFO);
        return;
      }
      JumptapAdaptor.LOG.logWarning(JumptapAdaptor.TAG, "Jumptap adaptor was garbage collected or adaptor stopped. Can not continue from onLaunchActivity", new Object[0]);
    }

    public void onNewAd(JtAdView paramJtAdView, int paramInt, String paramString)
    {
      JumptapAdaptor localJumptapAdaptor = (JumptapAdaptor)this.mAdaptor.get();
      if ((localJumptapAdaptor != null) && (!localJumptapAdaptor.isStopped()))
      {
        localJumptapAdaptor.getAdaptorListener().didLoad("jumptap", this.mIsInterstitial);
        if ((this.mIsInterstitial) && (!localJumptapAdaptor.mConfigurator.isPrecacheInterstitial()))
        {
          localJumptapAdaptor.getAdaptorListener().shownFullscreen(JumptapAdaptor.FULLSCREEN_INFO);
          localJumptapAdaptor.showActivity();
        }
        return;
      }
      JumptapAdaptor.LOG.logWarning(JumptapAdaptor.TAG, "Jumptap adaptor was garbage collected or adaptor stopped. Can not continue from onNewAd", new Object[0]);
    }

    public void onNoAdFound(JtAdView paramJtAdView, int paramInt)
    {
      JumptapAdaptor localJumptapAdaptor = (JumptapAdaptor)this.mAdaptor.get();
      if ((localJumptapAdaptor != null) && (!localJumptapAdaptor.isStopped()))
      {
        localJumptapAdaptor.getAdaptorListener().failedToLoad("jumptap", this.mIsInterstitial, "No ad found.");
        return;
      }
      JumptapAdaptor.LOG.logWarning(JumptapAdaptor.TAG, "Jumptap adaptor was garbage collected or adaptor stopped. Can not continue from onNoAdFound", new Object[0]);
    }

    public void onReturnFromActivity(JtAdView paramJtAdView, int paramInt)
    {
    }
  }
}

/* Location:           E:\android\Toy Defense 2_dex2jar.jar
 * Qualified Name:     com.burstly.lib.component.networkcomponent.jumptap.JumptapAdaptor
 * JD-Core Version:    0.6.2
 */